/*
 * @(#)FileTreeCellRender.java   09/09/13
 *
 * Copyright (C) 2009 Ecole des Mines d'Ales
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contact: yulinz88@gmail.com
 *
 *
 *
 */



package fr.ema.arch3d.gea.mainGUI.fileDirectory;

import fr.ema.arch3d.gea.Evolution;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 * Class description
 *
 *
 * @version        1.0, 09/09/13
 * @author         Huaxi (Yulin) ZHANG
 */
public class FileTreeCellRender extends DefaultTreeCellRenderer {

    /** Field description */
    ImageIcon icon = null;

    /** Field description */
    String str = null;

    /*
     *  (non-Javadoc)
     * @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.<b style="color:black;background-color:#ffff66">JTree</b>, java.lang.Object, boolean, boolean, boolean, int, boolean)
     */
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
            boolean leaf, int row, boolean hasFocus) {

        // TODO Auto-generated method stub
        // Set the icon for component nodes.
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

        FileNode node = (FileNode) value;

//      if(node.isLeaf()){
        setIcon(node.getIcon());

//      return this;
//         }
        return this;
    }

    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = Evolution.class.getResource(path);

        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);

            return null;
        }
    }

    /*
     *  private ImageIcon scale(Image src, double scale) {
     *    int w = (int)(scale*src.getWidth(this));
     *    int h = (int)(scale*src.getHeight(this));
     *    int type = BufferedImage.TYPE_INT_RGB;
     *    BufferedImage dst = new BufferedImage(w, h, type);
     *    Graphics2D g2 = dst.createGraphics();
     *    g2.drawImage(src, 0, 0, w, h, this);
     *    g2.dispose();
     *    return new ImageIcon(dst);
     * }
     */
}
